package com.example.demo.filter;

import com.example.demo.context.BaseContext;
import com.example.demo.properties.JwtProperties;
import com.example.demo.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;

@WebFilter("/*" )
@Component
@Slf4j
@RequiredArgsConstructor
public class LoginCheckInterceptor extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        String url = request.getRequestURL().toString();
        log.info("请求的url: {}",url);
        String token = request.getHeader("JWT-Token");
        logger.info("this is token");
        System.out.println(token);
        if(!StringUtils.hasText(token)){

            filterChain.doFilter(request, response);
            return;
        }

        filterChain.doFilter(request, response);
    }
}